<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8" />
<title>Hello World!</title>
</head>
<body>
	<p>admin</p>

	<button onclick="getMe()">获取本人信息</button>
	<button onclick="get()">评分信息</button>
	<button onclick="getStage()">获取某个阶段打分信息</button> 
	<a href="http://localhost:8080/admin/grade/one_excel?stageId=2">获取某个阶段打分信息Excel</a> 
	<button onclick="getAllStage()">获取所有阶段打分信息</button> 
	<a href="http://localhost:8080/admin/grade/allexcel?scoreInfoId=1">获取所有阶段打分信息Excel</a> 
	 
	<p>管理功能</p>
	候选人信息
	<input type ="file" id= "candidateFile" name ="candidateFile" >
	<button onclick="importCandidate()">上传候选人数据</button> 
	 
	 <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
	<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
	<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
	<script src="../js/ip.js"></script>
	<script type="text/javascript">
         
        var stageId = 1;
        var sort = 0;
        var scoreInfoId = 1;
        var refreshid = 7;
        function getMe() { 
			var postaddress = '/current'; 
			var sendData = new Object();
			sendData.scoreInfoId = scoreInfoId;
			sendData.sort = sort;
			$.ajax({
				//几个参数需要注意一下
				type: "get", //方法类型
				dataType: "json", //预期服务器返回的数据类型
				url: postaddress, //url 
				success: function(result) {
					console.log(result); //打印服务端返回的数据 
					if (result.code == 0)
					{
						alert(result.data.name);
					} else
						{ 
						alert("错误"); 
						}
				}, 
				error: function() {

				}
			});
		}
    	function get() { 
			var postaddress = '/admin/grade/get'; 
			var info = new Object(); 
			info.stageId = 1;
			info.refreshid = refreshid;
			console.log(JSON.stringify(info));
			$.ajax({
				//几个参数需要注意一下
				type: "POST", //方法类型
				dataType: "json", //预期服务器返回的数据类型
				contentType: "application/json;charset=utf-8",
				url: postaddress, //url
				data: JSON.stringify(info),
				success: function(result) {
					console.log(result); //打印服务端返回的数据 
					alert(result.data);
				}, 
				error: function() { 
						alert("错误");  
				}
			});
		}
        
				function getStage() { 
					var info = new Object();
					info.scoreInfoId = 1;
					info.stageId = stageId;
					info.sort = sort;
					info.candidateId = 1;
					info.fraction = 90;
					console.log(JSON.stringify(info));
					var postaddress = '/admin/grade/one_stage';
					console.log(JSON.stringify(info));
					$.ajax({
						//几个参数需要注意一下
						type: "POST", //方法类型
						dataType: "json", //预期服务器返回的数据类型
						contentType: "application/json;charset=utf-8",
						url: postaddress, //url
						data: JSON.stringify(info) ,
						success: function(result) {
							console.log(result); //打印服务端返回的数据 
							alert(result.data);
						}, 
						error: function() {
							alert(result.msg);
						}
					});
				}
				
				 
				
				function getAllStage() { 
					var info = new Object(); 
					info.scoreInfoId = scoreInfoId; 
					console.log(JSON.stringify(info));
					var postaddress = '/admin/grade/allgrade';
					console.log(JSON.stringify(info));
					$.ajax({
						//几个参数需要注意一下
						type: "POST", //方法类型
						dataType: "json", //预期服务器返回的数据类型
						contentType: "application/json;charset=utf-8",
						url: postaddress, //url
						data: JSON.stringify(info) ,
						success: function(result) {
							console.log(result); //打印服务端返回的数据 
							if (result.code == 0)
							{
								alert(result.data);
							} 
						}, 
						error: function() {
							alert(result.msg);
						}
					});
				}
				
				
			 
				
			    function importCandidate(url) { 
			    	   var fileObj = document.getElementById("candidateFile").files[0]; // js 获取文件对象
                                 console.log(fileObj);
                                 var formFile = new FormData(); 
                                 formFile.append("file", fileObj); //加入文件对象
                   
                                 $.ajax({
                                     type: "POST",
                                     url: "/candidate/import",
                                     data: formFile,
                                     dataType:'json',
                                     async: false,  
                                     cache: false,  
                                     contentType: false,  //必须false才会自动加上正确的Content-Type
                                     processData: false,  //必须false才会避开jQuery对 formdata 的默认处理
                                     error: function(request) {
                                         bootbox.alert("网络异常");
                                       },
                                     success: function(data){
 					                                    　　    if (data.code == 0) {
 					                                    　　        alert("上传成功!");
                                            
                                     　　　　} else {
                                     　　　　    alert("上传失败!");
                                     　　　　}
						 }
                                 });
                               
                            
                }
			</script>
</body>
</html>